<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="checkbox" id="ck" onclick="fn()"/>
		<hr />
		<div id="div">
			<input type="checkbox"/><br />
			<input type="checkbox" /><br />
			<input type="checkbox" /><br />
			<input type="checkbox" /><br />
			<input type="checkbox" />
		</div>
        <script type="text/javascript">
            function fn(){
				//根据id获得对象
              let  allCheck= document.getElementById('ck').checked;
			  //验证allCheck是否为true
console.log(allCheck);
				//根据标签获得对象
			  let divCheck= document.getElementById('div').children
			  //循环遍历并使每个divCheck[i].checked=true
				for(let i=0;i<divCheck.length;i++){
					divCheck[i].checked=true;
				}
			  }           
	
        </script>
	</body>
</html>